package com.acwing.partition4;

import java.io.*;
import java.util.*;

/**
 * @author `RKC`
 * @date 2022/1/28 15:46
 */
public class AC396矿场搭建 {

    private static final int N = 1010, M = 1010;
    private static int[] h = new int[N], e = new int[M], ne = new int[M];

    private static int n = 0, m = 0, idx = 0, timestamp = 0, vDccCnt = 0, root = 0;
    private static Map<Integer, List<Integer>> vDccMap = new HashMap<>();
    private static int[] dfn = new int[N], low = new int[N];
    private static Deque<Integer> stk = new ArrayDeque<>(N);
    private static boolean[] cut = new boolean[N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int num = 1;
        while (true) {
            m = Integer.parseInt(reader.readLine());
            if (m == 0) break;
            idx = n = timestamp = vDccCnt = 0;
            for (int i = 0; i < N; i++) {
                h[i] = -1;
                dfn[i] = low[i] = 0;
                cut[i] = false;
            }
            for (int i = 0; i < m; i++) {
                String[] s = reader.readLine().split("\\s+");
                int a = Integer.parseInt(s[0]), b = Integer.parseInt(s[1]);
                n = Math.max(n, Math.max(a, b));
                add(a, b);
                add(b, a);
            }
            for (root = 1; root <= n; root++) {
                if (dfn[root] == 0) tarjan(root);
            }
            int ans = 0;
            long c = 0;
            //遍历每一个v-dcc
            for (int i = 1; i <= vDccCnt; i++) {
                int cnt = 0;
                List<Integer> item = vDccMap.get(i);
                for (int j = 0; j < item.size(); j++) {
                    //TODO 未完成
                    if (cut[item.get(i)]) {
                        cnt++;
                    }
                }
                if (cnt == 0) {
                    if (item.size() > 1) {
                        ans += 2;
                        c *= item.size() * (item.size() - 1) / 2;
                    } else ans++;
                } else if (cnt == 1) {
                    ans++;
                    c *= item.size() - 1;
                }
            }
            writer.write(String.format("Case %d: %d %d\n", num++, ans, c));
        }
        writer.flush();
    }

    private static void tarjan(int u) {
        dfn[u] = low[u] = ++timestamp;
        stk.addLast(u);
        if (u == root && h[u] == -1) {
            //当前点是孤立点
            vDccCnt++;
            List<Integer> p = vDccMap.getOrDefault(vDccCnt, new ArrayList<>());
            p.add(u);
            vDccMap.put(vDccCnt, p);
            return;
        }
        int cnt = 0;
        for (int i = h[u]; i != -1; i = ne[i]) {
            int v = e[i];
            if (dfn[v] == 0) {
                tarjan(v);
                low[u] = Math.min(low[u], low[v]);
                if (dfn[u] <= low[v]) {
                    cnt++;
                    //当前点是割点
                    if (u != root || cnt > 1) cut[u] = true;
                    vDccCnt++;
                    int y = -1;
                    List<Integer> p = vDccMap.getOrDefault(vDccCnt, new ArrayList<>());
                    do {
                        y = stk.pollLast();
                        p.add(y);
                    } while (v != y);
                    p.add(u);
                    vDccMap.put(vDccCnt, p);
                }
            } else low[u] = Math.min(low[u], dfn[v]);
        }
    }

    private static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }
}
